#!/bin/sh

work_dir=/home/gtwy/tmp
proj=wuye

while getopts "p:" opt
do
        case $opt in
                p ) profile=$OPTARG;;
                ? ) echo "error"
                    exit 0;;
        esac
done

if [ -z "$profile" ]
then
	echo "---usage: -p profile"
	exit 0
fi

if [ ! -d  ${work_dir} ]
then
	mkdir ${work_dir}
fi
cd ${work_dir}

if [ -d $proj ]
then
	cd $proj
	svn --username zhouyue --password zy@321 update
else
	svn --username zhouyue --password zy@321 checkout svn://test.youpinfood.net/web/$proj
fi

echo "---maven install with profile: $profile"
mvn -P${profile} clean install

if [ "$profile" = "product" ]
then
	tomcat=/home/gtwy/tomcat
else
	tomcat=/home/gtwy/tomcat_int
fi
echo "---copy war to $tomcat"
rsync -av ${work_dir}/$proj/target/ROOT.war $tomcat/webapps

echo "---restart $tomcat"
$tomcat/restart_tomcat.sh
echo "---end"

